<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head><title></title>

        <link type="text/css" href="../../../Styles/IndustrialDashboard.css" rel="stylesheet" />
        <link type="text/css" href="../Styles/IndustrialGrid.css" rel="stylesheet"  />    
        <link type="text/css" href="../../DropDownPicker/Styles/DropDownPicker.css" rel="stylesheet" />
        <link type="text/css" href="../../CalendarPicker/Styles/CalendarPicker.css" rel="stylesheet" />        

        <script src="../../../Scripts/IndustrialDashboard.js" type="text/javascript"></script>
        <script src="../../DropDownPicker/Scripts/DropDownPicker.js" type="text/javascript"></script>        
        <script src="../../CalendarPicker/Scripts/CalendarPicker.js" type="text/javascript"></script>        
        <script src="IndustrialGrid.js" type="text/javascript"></script>        

        <style type="text/css">
            body{margin:0px;padding:0px}            
            .reportContainer{margin-top:5px;background:#FFFFFF;background-image:none; width:90%; padding:10px;height:auto; }
            .spContainer{margin-top:5px;background:#FFFFFF;background-image:none; height:150px; width:270px; padding:10px;}
            .cpContainer{margin-top:5px;background:#FFFFFF;height:150px; width:180px; padding:10px;}            
        </style>                     
    
    </head>
    <body>
        <center>
            <div id="div1" style="margin:0px;padding:0px;left:0px;top:0px;width:100%;position:absolute">           
                    <div class="reportContainer" id="pReportContainer"> 
                        <div id="pIG"></div> 
                    </div>
            </div>
        </center>   
        
        <script language="javascript" type="text/javascript">                    
           function resizeIframe() {
                window.top.document.getElementById('wpIframe').height = ""+document.getElementById('div1').offsetHeight+"px";
           }
           
           var props = window.top.document.getElementById('wpIframe').name.split('?');                             
           
           var url = props[0];
           var sProcedure = props[1];
           var pickerChoice = props[2];
           var ddpSp = props[3];
           var ddpFilter = props[4];
           var svcUrl = url + '/DALService.svc/CallProcedure';                                  
            
          attachDomReadyEventHandler(function () {                                            
               var ig = new IndustrialGrid(document.getElementById('pIG'),
                                    { 'URL': svcUrl, 'Procedure': sProcedure});          

               switch(pickerChoice) {
                    case "None" : {
                       var SQLParams = new SQLParameters();
//                        SQLParams.add('StartDate', 'DATETIME', '1950-01-01 00:00');
//                        SQLParams.add('EndDate', 'DATETIME', '2100-01-01 00:00');
                        ig.refreshData(SQLParams);   
                        break;
                    }               
                    case "DropdownPicker" : {
                        if(ddpSp == null || ddpFilter == null || ddpSp == "" || ddpFilter == "") {                            
                            var salida = document.createElement('p'); salida.style.color = "Red"; salida.style.fontFamily = "Tahoma"; salida.style.fontSize = "12";
                            salida.innerHTML = "Please enter a valid store procedure and filter for the DropDown Picker.";
                            document.getElementById('div1').appendChild(salida);                            
                        } else {
                           try {
                                var ddpCont = document.createElement('div');
                                ddpCont.id = "pDDP";
                                document.getElementById('div1').insertBefore(ddpCont, document.getElementById('pReportContainer'));

                                if(ddpFilter != "" && ddpFilter != null) {
                                    var ddpFilterArray = ddpFilter.split(",");
                                }

                                var ddp = new DropDownPicker(ddpCont,
                                                            { 'URL': svcUrl, 'Procedure': ddpSp
                                                                , 'events': { 'onComplete': refreshIndustrialGrid
                                                                            , 'onChange': refreshIndustrialGrid
                                                                }
                                                            });    
                                ddp.refreshData();                   
                                    function refreshIndustrialGrid() {
                                        try {                                        
                                            ig.refreshData(ddp.getResults(ddpFilterArray));
                                            resizeIframe();
                                        }
                                        catch (Error) { }
                                   }                      
                             } catch(Error) {}      
                        }
                        break;
                    }    
                    case "CalendarPicker" : {
                        try {

                            var d1 = document.createElement('div');
                            var d2 = document.createElement('div');
                            d1.className = "cpContainer";
                            d2.id = "calendarContainer";
                            d1.appendChild(d2);
                            document.getElementById('div1').insertBefore(d1, document.getElementById('pReportContainer'));
                            var cp = new CalendarPicker(d1, { 'URL': svcUrl, 'Procedure': sProcedure
                                                                , 'events': { 'onComplete': refreshCalendarPicker
                                                                            , 'onChange': refreshCalendarPicker
                                                                }
                                                            });  

                                function refreshCalendarPicker() {
                                    try {                       
                                        ig.refreshData(cp.getResults());
                                        resizeIframe();
                                    }
                                    catch (Error) { }
                                }
                        } catch(Error) {}
                        break;
                    }
//                    case "ScopePicker" : {          
//                        try {              
//                            var d1 = document.createElement('div');
//                            var d2 = document.createElement('div');
//                            d1.className = "spContainer";
//                            d2.id = "scopePickerContainer";
//                            d1.appendChild(d2);
//                            document.getElementById('div1').insertBefore(d1, document.getElementById('pReportContainer'));

//                            var sp = new ScopePicker(d2,{ 'URL': svcUrl, 'Procedure': sProcedure
//                                                                , 'events': { 'onComplete': refreshScopePicker
//                                                                            , 'onChange': refreshScopePicker
//                                                                }
//                                                            });  
//                            function refreshScopePicker() {
//                               try {                        
//                                   ig.refreshData(sp.getResults());
//                                   resizeIframe();
//                                }
//                                catch (Error) { }
//                            }
//                        } catch(Error) {}
//                        break;
//                    }           
                 }
                      resizeIframe();   
           });                                                                                              
        </script>
    </body>
</html>    